package com.example.netlib.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.netlib.BaseHttpResultBean;
import com.example.netlib.ErrorService;
import com.example.netlib.R;
import com.example.netlib.netwrapper.LocalHttpClientHolder;
import com.szlanyou.thirdsdk.retrofit.client.HttpClient;

import java.io.IOException;

import retrofit2.Call;
import retrofit2.Response;

public class ErrorTestActivity extends AppCompatActivity {
    private static final String TAG = "ErrorTestActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_error_test);
    }

    public void test(View view) {
        new Thread(){
            @Override
            public void run() {
                HttpClient httpClient = LocalHttpClientHolder.getInstance().getHttpClient();
                Call<BaseHttpResultBean> call = httpClient.getService(ErrorService.class).errorRequest();
                Response<BaseHttpResultBean> execute = null;
                try {
                    execute = call.execute();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if(execute != null){
                    BaseHttpResultBean body = execute.body();
                    Log.d(TAG,"errorTest " + body);
                }else{
                    Log.e(TAG,"response is null ");
                }
            }
        }.start();
    }
}